<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PlaceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */


    public function getDevrone(Request $request){
        //获取登录账号
//        $id = 89;
        $id = $request->session()->get('id');
        //获取账号下所有位置
        $place = DB::table('place') -> where('member_id',$id) -> get();
//        dd($place);
        return view('home.place.device-room1',['place'=>$place]);
    }

    public function getDevrtwo(){
        $data = Db::table('place_icon')->get();
        return view('home.place.device-room2',['data'=>$data]);
    }

    public function getDevrthree(){
        return view('home.place.device-room3');
    }

    public function getAdd(Request $request){
//        $info = $request -> except('_token');
        $icon_id = $request -> input();
       $info = Db::table('place_icon')->where('id',$icon_id)->first();
       $id = $request->session()->get('id');
//       dd($id);
       $data=[
           'icon'=>$info['name'],
           'name'=>$info['alias'],
           'member_id'=>$id,
       ];
//       dd($data);
      $rec = Db::table('place')->insert($data);
      if($rec){
          return redirect('/home/place/devrone')->with('保存成功');
      }
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
